#include <iostream>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;

namespace fastio{
    struct{template<typename T>operator T(){
        T x=0;char f=0,c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=1;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+(c^48);c=getchar();}
        return f?-x:x;
    }}in;int stk[40],tp;
    template<typename T>void out(T x,char c=0){
        if(x<0)putchar('-'),x=-x;
        do stk[++tp]=x%10,x/=10;while(x);
        while(tp)putchar(stk[tp--]^48);
        if(c)putchar(c);
    }
}using fastio::in;using fastio::out;

const int N = 1000005,mod = 998244353;
int fac[N],inv[N];
int a[N];
int n,m;

int ksm(int a,int b){
    int ans = 1;
    while(b){
        if(b&1)
            ans = ans*a%mod;
        a = a*a%mod;
        b >>= 1;
    }
    return ans;
}

int C(int a,int b){
    if(a<0||b<0||b>a)
        return 0;
    return fac[a]*inv[b]%mod*inv[a-b]%mod;
}

signed main(){
    freopen("count.in","r",stdin);
    freopen("count.out","w",stdout);
    inv[0] = fac[0] = 1;
    for(int k=1;k<N;k++)
        fac[k] = fac[k-1]*k%mod;  
    inv[N-1] = ksm(fac[N-1],mod-2);
    for(int k=N-2;k;k--)
        inv[k] = inv[k+1]*(k+1)%mod;
    n = in,m = in;

    a[0] = 1;
    for(int k=1;k<=n;k++)
        a[k] = (int)in+1;
    int ans = 0;
    for(int k=1;k<=n;k++){
        for(int j=a[k-1];j<a[k];j++)
            ans = (ans+C(n+m-k-j,n-k))%mod;
        if(a[k]<a[k-1]){
            ans--;
            break;
        }
    }
    out(ans);
    return 0;
}